--- @param extension Package
--- @param HY HY_Utility
--- @param U Utility
return function(extension, HY, U)
    local hy_kamishirasawa_keine = General:new(extension, "hy_kamishirasawa_keine", "ten_k", 3, 3, General.Female)
    local rewrite_history = fk.CreateSkill {
        name = "rewrite_history",
        tags = {
            Skill.Charge,
        }
    }
    local effect = rewrite_history:addEffect(fk.EnterDying, {
        can_trigger = function(self, event, target, player, data)
            return player:hasSkill(rewrite_history.name) and player:getMark("skill_charge") > 0
        end,
        on_cost = function(self, event, target, player, data)
            return player.room:askToSkillInvoke(player, {
                skill_name = rewrite_history.name,
                prompt = "rewrite_history_prompt::" .. target.id .. ":" .. math.min(player:usedEffectTimes(self.name, Player.HistoryGame) + 1, 5)
            })
        end,
        on_use = function(self, event, target, player, data)
            local room = player.room
            if player:getMark("@rewrite_history") < 5 then
                room:addPlayerMark(player, "@rewrite_history", 1)
            end
            U.skillCharged(player, -1)
            local n = #target:getCardIds("h") - math.min(player:usedEffectTimes(self.name, Player.HistoryGame), 5)
            if n > 0 then
                room:askToDiscard(target, {
                    min_num = n,
                    max_num = n,
                    skill_name = rewrite_history.name,
                    cancelable = false
                })
            else
                target:drawCards(-n, rewrite_history.name)
            end
        end,
    })
    rewrite_history:addEffect(fk.AfterCardsMove, {
        can_trigger = function(self, event, target, player, data)
            return player:hasSkill(rewrite_history.name) and table.any(data, function(move)
                return move.from and not move.from.dead and #move.from:getCardIds("h") == 0 and table.any(move.moveInfo, function(info)
                    return info.fromArea == Card.PlayerHand
                end)
            end)
        end,
        on_cost = Util.TrueFunc,
        on_use = function(self, event, target, player, data)
            local room = player.room
            U.skillCharged(player, 1)
            room:recover({
                who = player,
                num = 1,
                skillName = rewrite_history.name,
                recoverBy = player,
            })
        end
    })
    rewrite_history:addAcquireEffect(function(self, player, is_start)
        U.skillCharged(player, 1, 2)
        player.room:addPlayerMark(player, "@rewrite_history", math.min(player:usedEffectTimes(effect.name, Player.HistoryGame) + 1, 5))
    end)
    rewrite_history:addLoseEffect(function(self, player, is_death)
        U.skillCharged(player, 0, -2)
    end)
    local erase_history = fk.CreateSkill {
        name = "erase_history",
    }
    erase_history:addEffect(fk.TargetSpecified, {
        can_trigger = function(self, event, target, player, data)
            return player:hasSkill(erase_history.name) and data.firstTarget and data.from ~= player and data.card.trueName == "slash" and #player:getCardIds("h") > 0 and
                player:canUseTo(Fk:cloneCard("slash"), data.from, { bypass_times = true, bypass_distances = true })
        end,
        on_cost = function(self, event, target, player, data)
            return player.room:askToSkillInvoke(player, {
                skill_name = erase_history.name,
                prompt = "erase_history_prompt::" .. data.from.id
            })
        end,
        on_use = function(self, event, target, player, data)
            local room = player.room
            local card = Fk:cloneCard("slash")
            card:addSubcards(player:getCardIds("h"))
            table.insertIfNeed(card.skillNames, erase_history.name)
            player.tag["erase_history_target"] = data.from
            player.tag["erase_history_card"] = data.card
            room:useCard({
                from = player,
                card = card,
                tos = { data.from },
                extraUse = true,
            })
        end
    })
    erase_history:addEffect(fk.CardUseFinished, {
        late_refresh = true,
        can_refresh = function(self, event, target, player, data)
            return table.contains(data.card.skillNames, erase_history.name) and data.from == player
        end,
        on_refresh = function(self, event, target, player, data)
            player.tag["erase_history_target"] = nil
            player.tag["erase_history_card"] = nil
        end,
        can_trigger = function(self, event, target, player, data)
            return player:hasSkill(erase_history.name) and table.contains(data.card.skillNames, erase_history.name) and data.damageDealt and
                data.damageDealt[player.tag["erase_history_target"]] > 0
        end,
        on_cost = Util.TrueFunc,
        on_use = function(self, event, target, player, data)
            local e = player.room.logic:getCurrentEvent()
            while e do
                e = e:findParent(GameEvent.UseCard)
                if e and e.data.card and e.data.card == player.tag["erase_history_card"] then
                    break
                end
            end
            if e then
                e.data.nullifiedTargets = player.room:getAlivePlayers()
            end
        end,
    })
    extension:loadSkillSkels { rewrite_history, erase_history }
    hy_kamishirasawa_keine:addSkills { "rewrite_history", "erase_history" }
    Fk:loadTranslationTable {
        ["hy_kamishirasawa_keine"] = "上白泽慧音",
        ["#hy_kamishirasawa_keine"] = "史界师长",
        ["designer:hy_kamishirasawa_keine"] = "黑曜人形",
        ["illustrator:hy_kamishirasawa_keine"] = "kaze",
        ["cv:hy_kamishirasawa_keine"] = "",

        ["rewrite_history"] = "覆史",
        [":rewrite_history"] = "蓄力技（1/2），一名角色进入濒死状态时，你可以令其将手牌数调整至X（X为此技能以此法发动过的次数+1且至多为5）。一名角色失去所有手牌后，你获得1点蓄力点并回复1点体力。",
        ["rewrite_history_prompt"] = "覆史：你可以令%dest将手牌数调整至%arg",
        ["@rewrite_history"] = "覆史",

        ["erase_history"] = "除迹",
        [":erase_history"] = "其他角色使用【杀】指定目标后，你可以将所有手牌当作【杀】对其使用，若此【杀】对其造成了伤害，你令其使用的【杀】无效。",
        ["erase_history_prompt"] = "除迹：你可以将所有手牌当作【杀】对%dest使用",
    }
end
